<!DOCTYPE HTML>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="console/header">
</head>
<body>
<section class="content-header">
    <h1>管理员管理</h1>
    <small>列表管理</small>
</section>
<section class="content table-content">
    <table id="dataGrid"></table>
</section>
<div id="toolbar">
    <a href="/console/admin/from" class="btn btn-primary">添加用户</a>
</div>
<div th:include="console/footer"></div>
</body>
<script type="text/javascript">
    $table = $("#dataGrid");
    $(function () {
        initDataGrid();
    });
    function initDataGrid(){
        $table.bootstrapTable({
            height : tableModel.getHeight(),
            idField : "uid",
            columns : [[
                {title: "用户名", field: "username" },
                {title: "角色", field: "roleList", formatter : getRole},
                {title: "状态", field: "state",formatter : tableModel.getState},
                {title: "创建时间", field: "createdAt", sortable: true},
                {title: "更新日期", field: "updatedAt", sortable: true},
                {title: "操作", field: "operate", align: 'center', events: operateEvents, formatter: operateFormatter}
            ]],
            url : '/console/admin/list',
            queryParams: function(params){
                return params;
            },
            responseHandler : function (res) {
                return {
                    rows : res.result.pageInfo.list,
                    total : res.result.pageInfo.total
                }
            },
            search : true,
            searchOnEnterKey : true,
            sortName : 'createdAt',
            sortOrder : 'asc',
            pagination : true,
            sidePagination : 'server',
            pageSize: 20,
            pageList : [20, 40, 50, 100],
            toolbar : "#toolbar",
            showRefresh : true,
            showToggle : true
        });
    }

    function getRole(value,row,index) {
        if(row.isSystem == 1){
            return "超级管理（不受角色限制）"
        }else{
            return $.map(value,function (v) {
                return v.roleName;
            }).join(",");
        }

    }

    function operateFormatter(value, row, index) {
        if(row.isSystem == 0){
            return [
                '<a href="/console/admin/from?uid='+row.uid+'" >',
                '<i class="glyphicon glyphicon-edit"></i>修改',
                '</a>  ',
                '<a class="remove" href="javascript:void(0);">',
                '<i class="glyphicon glyphicon-remove"></i>删除',
                '</a>'
            ].join('');
        }
    }

    window.operateEvents = {
        'click .remove': function (e, value, row, index) {
            operaModel.delRow(row.uid, '/console/admin/delete', 'uid');
        }
    };
</script>
</html>